package com.xcalendar.servlets;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.appengine.api.datastore.KeyFactory;
import com.xcalendar.constant.XConstants;
import com.xcalendar.database.table.Event;
import com.xcalendar.database.table.User;
import com.xcalendar.management.EventManager;
import com.xcalendar.managementImpl.EventManagerImpl;

@SuppressWarnings("serial")
public class ResizeEventController extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// HttpSession session = request.getSession();
		// User user = (User)session.getAttribute(XConstants.SESSION_USER);
		EventManager eventManager = new EventManagerImpl();

		String eventId = request.getParameter("eventIdResize");
		String eventTitle = request.getParameter("eventTitleResize");
		String description = request.getParameter("eventDescriptionResize");
		String start = request.getParameter("eventStartResize");
		String end = request.getParameter("eventEndResize");
		Date dStart = new Date(start);
		Date dEnd = new Date(end);
		dStart.setHours(dStart.getHours() + 1);
		dEnd.setHours(dEnd.getHours() + 1);
		Event event = new Event();
		event.setKey(KeyFactory.stringToKey(eventId));
		event.setTitle(eventTitle);
		event.setDescription(description);
		event.setStartTime(dStart);
		event.setEndTime(dEnd);
		eventManager.updateEvent(event);
		response.setContentType("text/plain");
		response.getWriter().println("resizeSuccessfully");
	}

}
